<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 * 订单接口 测试类
 */

namespace app\test\controller;

use app\utils\BoyeService;
use app\test\controller\Ava;

class Orders extends Ava
{
	//测试 - 支付完成
	public function testPaySuc(){
		if(IS_AJAX){
			$data = [
				'uid'  		  => I('post.uid',''),
				'code' 		  => I('post.code',''),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_Orders_testPaySuc',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_testPaySuc');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['code','T1469689177U143P13',LL('need-mark orders pay-code')],
			]);
			echo $this->display('ava/test');
		}
	}
	//评论订单
	public function comment()
	{
		if(IS_AJAX){
			$data = [
				'pid'        => I('post.pid',''),
				'psku_id'    => I('post.psku_id',''),
				'group_id'   => I('post.group_id',''),
				'package_id' => I('post.package_id',''),
				'uid'        => I('post.uid',''),
				'order_code' => I('post.order_code',''),
				'score' 		 => I('post.score',''),
				'express_score'  => I('post.express_score',''),
				'delivery_score' => I('post.delivery_score',''),
				'service_score'  => I('post.service_score',''),
				'comment'    => $_POST['comment'],//I('post.comment','',null),
				'attachments'=> I('post.attachments',''),
				'api_ver'    => $this->api_ver,
				'notify_id'  => $this->notify_id,
				'alg'        => $this->alg,
				'type'       => 'BY_Orders_comment',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_comment');
			$this->assign('field',[
				['api_ver',101,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['pid','28,2',LL('need-mark product ID')],
				['psku_id','1251,1204',LL('need-mark product sku ID')],
				['group_id','0,0',LL('need-mark product group ID')],
				['package_id','0,0',LL('need-mark product package ID')],
				['order_code','1621314202692905582Y',LL('need-mark orders code')],
				['score','4,2',LL('need-mark order-comment-score')],
				['comment[]','good-1',LL('need-mark order-comment-content')],
				['comment[]','good-2',LL('need-mark order-comment-content')],
				['attachments','494-1,2-495',L('order-comment-attach')],
				['express_score','4,2',LL('need-mark order-comment-score')],
				['delivery_score','4,2',LL('need-mark order-comment-score')],
				['service_score','4,2',LL('need-mark order-comment-score')],
			]);
			echo $this->display('ava/test');
		}
	}
	//查询物流信息 - web
	public function expressInfo(){
		//	if(IS_AJAX){
		// 		$data = array(
	  //       'username' => I('post.username',''),
	  //       "password" => I('post.password',''),
	  //       'api_ver'  =>$this->api_ver,
	  //       'notify_id'=>$this->notify_id,
	  //       'alg'			 =>$this->alg,
	  //       'type'		 =>'BY_User_login',
	  //     );

	  //     $service = new BoyeService();
	  //     $result = $service->callRemote("",$data,true);
	  //     echo $this->parseResult($result);
	  //   }else{
    	$this->assign('type','BY_Orders_');
	    // $this->assign('client_id',CLIENT_ID);
	    $this->assign('post_url',C('WEBVIEW_URL').'/express/viewOrder');
			$this->assign('field',[
				['order_code','16891819401679885A',LL('need-mark orders code')],
				['tpl','0',L('express-tpl')],
			]);
	    echo $this -> display('ava/express');
		// }
	}
	//根据购物车计算运费
	public function cost()
	{
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'address_id' => I('post.address_id',''),
				'cart_ids'   => I('post.cart_ids',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Freight_cost',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Freight_cost');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',42,LL('need-mark user ID')],
				['address_id',129,LL('need-mark address ID')],
				['cart_ids','494,495',LL('need-mark order-cart-ids')],
			]);
			echo $this->display('ava/test');
		}
	}
	//根据商品规格计算运费
	public function costSku()
	{
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'address_id' => I('post.address_id',''),
				'pid'        => I('post.pid',''),
				// 'psku_id'    => I('post.psku_id',''),
				'count'      => I('post.count',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Freight_costSku',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Freight_costSku');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['address_id',142,LL('need-mark address ID')],
				['pid','1,2',LL('need-mark product ids')],
				// ['psku_id','1281,1204',LL('need-mark product sku ids')],
				['count','1,1',LL('need-mark buy number')],
			]);
			echo $this->display('ava/test');
		}
	}
	//立即购买
	public function addBySkuNew(){
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'red_id'     => I('post.red_id',''),
				'coupon_id'  => I('post.coupon_id',''),
				// 'money'      => I('post.money',''),
				'pid'        => I('post.pid',''),
				'count'      => I('post.count',''),
				'psku_id'    => I('post.psku_id',''),
				'group_id'   => I('post.group_id',''),
				'package_id' => I('post.package_id',''),
				'note'       => I('post.note',''),
				'address_id' => I('post.address_id',''),
				'from'       => I('post.from',''),
				'api_ver'     => $this->api_ver,
				'notify_id'   => $this->notify_id,
				'alg'         => $this->alg,
				'type'        => 'BY_Orders_addBySkuNew',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);

		}else{
			$this->assign('type','BY_Orders_addBySkuNew');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['pid','1,2',LL('need-mark product ID')],
				['count',1,LL('need-mark product count')],
				['psku_id','1281,1204',LL('need-mark product sku ID')],
				['group_id','',L('group-id')],
				['package_id',1,L('package-id')],
				['red_id','',LL('redEnvelope ID')],
				['coupon_id','',LL('coupon ID')],
				// ['money','',L('wallet')],
				['note','',L('note')],
				['address_id',133,LL('need-mark address ID')],
				['from','',L('order-from')],
			]);
			echo $this->display('ava/test');
		}
	}
	//立即购买
	public function addBySku(){
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'red_id'     => I('post.red_id',''),
				'coupon_id'  => I('post.coupon_id',''),
				'money'      => I('post.money',''),
				'pid'        => I('post.pid',''),
				'count'      => I('post.count',''),
				'psku_id'    => I('post.psku_id',''),
				'group_id'   => I('post.group_id',''),
				'package_id' => I('post.package_id',''),
				'note'       => I('post.note',''),
				'address_id' => I('post.address_id',''),
				'from'       => I('post.from',''),
				'api_ver'     => $this->api_ver,
				'notify_id'   => $this->notify_id,
				'alg'         => $this->alg,
				'type'        => 'BY_Orders_addBySku',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);

		}else{
			$this->assign('type','BY_Orders_addBySku');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['pid','1,2',LL('need-mark product ID')],
				['count',1,LL('need-mark product count')],
				['psku_id','1281,1204',LL('need-mark product sku ID')],
				['group_id','',L('group-id')],
				['package_id',1,L('package-id')],
				['red_id','',LL('redEnvelope ID')],
				['coupon_id','',LL('coupon ID')],
				['money','',L('wallet')],
				['note','',L('note')],
				['address_id',133,LL('need-mark address ID')],
				['from','',L('order-from')],
			]);
			echo $this->display('ava/test');
		}
	}
	//生成订单
	public function add()
	{
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'red_ids'    => I('post.red_ids',''),
				'coupon_ids' => I('post.coupon_ids',''),
				'money'      => I('post.money',''),
				'notes'      => $_POST['notes'],//I('post.notes',''),
				'address_id' => I('post.address_id',''),
				'from'       => I('post.from',''),
				'cart_ids'   => I('post.cart_ids',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_add',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_add');
			$this->assign('field',[
				['api_ver',101,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['red_ids','',LL('redEnvelope ID')],
				['coupon_ids','',LL('coupon ID')],
				['money','',L('wallet')],
				['notes[]','1',LL('store1 note')],
				['notes[]','2',LL('store1 note')],
				['cart_ids','789-798-799',LL('need-mark order-cart-ids')],
				['address_id',133,LL('need-mark address ID')],
				['from','',L('order-from')],
			]);
			echo $this->display('ava/test');
		}
	}
	//生成订单
	public function addNew()
	{
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'red_ids'    => I('post.red_ids',''),
				'coupon_ids' => I('post.coupon_ids',''),
				// 'money'      => I('post.money',''),
				'notes'      => $_POST['notes'],//I('post.notes',''),
				'address_id' => I('post.address_id',''),
				'from'       => I('post.from',''),
				'cart_ids'   => I('post.cart_ids',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_addNew',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_addNew');
			$this->assign('field',[
				['api_ver',100,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['red_ids','',LL('redEnvelope ID')],
				['coupon_ids','',LL('coupon ID')],
				// ['money','',L('wallet')],
				['notes[]','1',LL('store1 note')],
				['notes[]','2',LL('store1 note')],
				['cart_ids','789-798-799',LL('need-mark order-cart-ids')],
				['address_id',133,LL('need-mark address ID')],
				['from','',L('order-from')],
			]);
			echo $this->display('ava/test');
		}
	}
	//分页查询
	public function query()
	{
		if(IS_AJAX){
			$data = [
				'uid'        => I('post.uid',''),
				'status'     => I('post.status',0),
				'page_no'    => I('post.page_no',1),
				'page_size'  => I('post.page_size',10),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_query',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_query');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',42,LL('need-mark user ID')],
				['status',0,LL('need-mark order-status')],
				['page_no',1,L('page')],
				['page_size',10,LL('page size')],
			]);
			echo $this->display('ava/test');
		}
	}
	//根据ID查询订单
	public function detail()
	{
		if(IS_AJAX){
			$data = [
				'oid'        => I('post.oid',''),
				'order_code' => I('post.order_code',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_detail',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_detail');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['oid',37,LL('orders ID')],
				['order_code','',LL('orders code')],
			]);
			echo $this->display('ava/test');
		}
	}
	//确认收货 uid+order_code
	public function sure()
	{
		if(IS_AJAX){
			$data = [
				'uid'        =>I('post.uid',''),
				'order_code' =>I('post.order_code',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_sure',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_sure');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',1,LL('need-mark user ID')],
				['order_code','16138105357571476605',LL('need-mark orders code')],
			]);
			echo $this->display('ava/test');
		}
	}
	//取消订单 uid+order_code
	public function cancel()
	{
		if(IS_AJAX){
			$data = [
				'uid'        =>I('post.uid',''),
				'order_code' =>I('post.order_code',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_cancel',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_cancel');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',1,LL('need-mark user ID')],
				['order_code','16138105357571476605',LL('need-mark orders code')],
			]);
			echo $this->display('ava/test');
		}
	}
	//取消订单 uid+order_code
	public function aftersale()
	{
		if(IS_AJAX){
			$data = [
				'uid'         =>I('post.uid',''),
				'order_code'  =>I('post.order_code',''),
				'reason'      =>I('post.reason',''),
				'refund_type' =>I('post.refund_type',''),
				'refund_money'=>I('post.refund_money',''),
				'goods_get'   =>I('post.goods_get',''),
				'note'        =>I('post.note',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_aftersale',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_aftersale');
			$this->assign('field',[
				['api_ver',101,LL('need-mark api version')],
				['uid',1,LL('need-mark user ID')],
				['order_code','16138105357571476605',LL('need-mark orders code')],
				['reason','',L('reason')],
				['refund_type',1,LL('need-mark order-refund-type')],
				['refund_money',0,LL('need-mark order-refund-money')],
				['goods_get',1,LL('need-mark order-refund-isget')],
				['note','',L('note')],
			]);
			echo $this->display('ava/test');
		}
	}
	//根据订单重新生成支付信息
	public function pay()
	{
		if(IS_AJAX){
			$data = [
				'uid'        =>I('post.uid',''),
				'oid'   		 =>I('post.oid',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_pay',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_pay');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',1,LL('need-mark user ID')],
				['oid',447,LL('need-mark orders ID')],
			]);
			echo $this->display('ava/test');
		}
	}
	//根据订单重新获取预支付信息
	public function rePay()
	{
		if(IS_AJAX){
			$data = [
				'uid'        =>I('post.uid',''),
				'order_code' =>I('post.order_code',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_rePay',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_rePay');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['order_code',';',LL('need-mark order-codes ID')],
			]);
			echo $this->display('ava/test');
		}
	}
	//准备支付信息
	public function payNow()
	{
		if(IS_AJAX){
			$data = [
				'uid'        =>I('post.uid',''),
				'order_code' =>I('post.order_code',''),
				'pay_type'   =>I('post.pay_type',''),
				'pay_money'  =>I('post.pay_money',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_payNow',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_payNow');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['order_code',';',LL('need-mark order-codes ID')],
				['pay_type','1',LL('need-mark pay-type')],
				['pay_money','0',LL('pay wallet-money')],
			]);
			echo $this->display('ava/test');
		}
	}
	//获取物流信息
	public function express()
	{
		if(IS_AJAX){
			$data = [
				'uid'        =>I('post.uid',''),
				'order_code' =>I('post.order_code',''),
				'api_ver'    =>$this->api_ver,
				'notify_id'  =>$this->notify_id,
				'alg'        =>$this->alg,
				'type'       =>'BY_Orders_express',
			];
			$service = new BoyeService();
			$result  = $service->callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_Orders_express');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',1,LL('need-mark user ID')],
				['order_code',447,LL('need-mark orders code')],
			]);
			echo $this->display('ava/test');
		}
	}
}